Copyright: C++Builder v.1.0 Copyright (c) 1997 Borland International, Inc.


Database Explorer: Overview

The Database Explorer is a hierarchical database browser with editing capabilities as described below. Each version of C++Builder ships with a different Database Explorer:

C++Builder version	Explorer name	Notes
Client/Server Suite	SQL Explorer	SQL enabled: accesses SQL databases on remote servers Data dictionary enabled.
Professional	Database Explorer	Access local databases, and  the Local InterBase Server (LIBS).With third party ODBC drivers, permits access to ODBC-compliant databases, but does not support extended SQL browsing. Data dictionary enabled.
Standard	Database Explorer	Access local databases.
When a feature is available in only one or two versions of the Database Explorer, it is indicated in the help topic.

Through a persistent connection to a database, the Database Explorer enables you to:

Browse database server-specific schema objects, including tables, fields, stored procedure definitions, triggers, and indexes.

Create, view, and edit data in existing tables.

Create and maintain database aliases.

Enter SQL statements to query a database.

Create and maintain data dictionaries and attribute sets (C++Builder Client/Server Suite and C++Builder Professional only).

 Other Database Explorer topics


The Explorer User Interface
The Database Explorer User Interface

The Database Explorer window displays database information in two panes.

The left pane is a tabbed object inspector that displays a hierarchical tree of database or data dictionary objects.

Note: 	For the C++Builder Standard edition, there are no tabs in the left pane of the Database Explorer because data dictionaries are not supported.

The right pane contains tabbed pages that display the contents of objects highlighted in the left pane.  The tabbed pages in the right pane vary depending on the type of object highlighted in the left pane.

A plus sign (+) beside an object in the left pane indicates that the object contains other objects below it. To see those objects, click the plus sign. When an object is expanded to show its child objects, the plus sign becomes a minus sign. To hide child objects, click the minus sign.

To view information about an object in the left pane, double-click the object. The right pane displays one or more tabbed pages of information about the object. For example, when a database alias is highlighted in the left pane, the right pane displays a Definition page that contains database Type, PATH, and DRIVER NAME parameters. Bolded parameters indicate a parameter that cannot be modified. All other parameters that appear in the right pane can be edited there.

The tabbed pages available in the right pane differ depending on the currently selected object in the left pane. The following table summarizes the pages available for each type of object:

Object	Pages
SQL database	Definition Enter SQL (C++Builder Client/Server only)
Local database	Definition Enter SQL (C++Builder Client/Server and C++Builder Professional only)
Tables (All tables in a database) Fields (All columns in a table) Indices (All indexes for a table) Validity Checks (All checks for a table) Referential Constraints (All constraints for a table) Security Specs (All specs for a table) Family Members (All files associated with a table)	Summary Enter SQL (C++Builder Client/Server and C++Builder Professional only)
Table (A single table in a database)	Definition Data Enter SQL (C++Builder Client/Server and C++Builder Professional only)
Field (A single column in a table) Index (A single index for a table) Validity Check (A single check for a table) Referential Constraint (A single constraint for a table) Security Spec (A single spec for a table) Family Member (A single member for a table)	Definition Enter SQL (C++Builder Client/Server and C++Builder Professional only)
Borland Database Engine (BDE) Alias	Definition Enter SQL (C++Builder Client/Server and C++Builder Professional only)

 Database Explorer user interface


Color-coded symbols

The following color-coded symbols appear to the left of objects in the left pane:

Icon	Meaning

Green box	The highlighted database is open.  You can view objects in the database.

Red arrow	The object is in editing mode.  There are changes in this object or in objects further down its tree that have not been applied.

Shining red arrow	The object is newly created.

Red X	This object is to be deleted.  When changes to this object or its parent object are applied the object is deleted.

 Database Explorer user interface


Tabbed pages

The selections you make in the left pane enable some or all of the following right pane tabbed pages:

Right pane pages	Description

Definition	Displays the parameters of the database alias, table, or field highlighted in the left pane.

Summary	Displays the database objects contained within the parent object highlighted in the left pane.

Data	Displays the data in a selected table.

Enter SQL	Displays a window in which you can enter SQL statements.

Text	Displays the text of SQL database triggers and stored procedures.

You can edit parameters on the Definition page if the parameter names appear in normal type. If parameter names appear in bold, they cannot be edited.

You can enter and edit records in a table on the Data page if the table permits write access.

 Database Explorer user interface


Menubar commands

The following tables define the commands available from each menu on the Explorer’s menubar.

Object menu	Description

Open	Open the highlighted object.

Close	Close the highlighted object.

New	Create a new instance of the highlighted object class.

Delete	Delete the highlighted object.

Rename	Change the name of an object.

Apply	Save the highlighted object, including all changes and pending deletes to objects within its tree.

Cancel	Cancel the current operation.

Exit	Exit the Database Explorer.

Most of these menu choices are also available from the SpeedMenu when you are editing in the Database Explorer.

Dictionary menu	Description

Select	Select an existing data dictionary from the Select a Dictionary dialog box.

Register	Register a new data dictionary in the Object Repository.

Unregister	Unregister a data dictionary in the Object Repository. Unregistering does not delete a data dictionary, but prevents it from appearing in the Select a Dictionary dialog  box.

New	Create a new data dictionary.

Delete	Removes a data dictionary.

Import from Database	Import table schema information from an existing database into a data dictionary.

Import from File	Imports table schema information from a flat file.

Export to File	Exports a data dictionary to a flat file. This option is useful for sharing data dictionaries among different  developers.

Edit menu	Description

Cut	Copy and remove the selected parameter or field data.

Copy	Copy but do not remove the selected parameter or field data.

Paste	Paste a cut or copied string into the selected field.

View menu	Description

Toolbar	If checked, the toolbar is displayed near the top of the Database Explorer. The toolbar offers a few convenient icon duplicating the functionality of menubar commands such as Open, Delete, Cancel, Apply, Explore Blobs.

Status Bar	If checked, a status bar appears at the bottom of the Database Explorer window. It states how many items are found in the object highlighted in the left pane.

Blob Explorer	This command (and the Explore Blobs toolbar icon) opens the Blob Explorer.  This window displays selected Blobs as a graphic image, or as data.

System Data	If checked, displays system data such as SQL server system tables, InterBase system indices and triggers, and so on.  If this is irrelevant to your purpose, you can uncheck this item.

Large Icons	If checked, displays as large icons in the right pane, the contents of objects highlighted in the left pane.

Small Icons	If checked, displays as small icons in the right pane, the contents of objects highlighted in the left pane.

List	If checked, displays as a list in the right pane, the contents of objects highlighted in the left pane.

Detail	If checked, displays as a list in the right pane, the contents of objects highlighted in the left pane.

Auto Arrange	Auto Arrange works as in the Windows 95 Explorer: it arranges icons in the summary page automatically if the page is resized.

Refresh	If enabled for the currently selected Database Explorer object, Refresh redraws the display of the object and its children.

Options menu	Description

Confirm Edits	If checked, a confirm dialog is displayed after performing any modifications.

Live Queries	If checked, the result set returned by queries is editable.  Same as RequestLive property of TQuery.

Sync Pages	If checked, the schema information of the selected database is imported into the selected dictionary when you switch from the database page to the dictionary page. You are prompted to confirm this operation if Confirm Edits is checked.

Help menu	Description

Contents	Displays the WinHelp contents window for Database Explorer help.

About	Version and copyright information about the Database Explorer (this item does not appear when you invoke the Database Explorer from the C++Builder IDE).

 Database Explorer user interface


SpeedMenu commands (left pane)

When you highlight an object in the left pane, you can right-click it to display a SpeedMenu.

Pop-up command	Description

Open	Expand the selected object to display its constituents

Close	Retract the constituents of the selected object.

Refresh	Update the Database Explorer display

New	Instantiate a new object of the selected class

Delete	Delete the selected object.

Rename	Rename the selected object.

Apply	Save modifications (including pending deletes) made to this object and to its children (objects in its tree).

Cancel	Undo last command or revert to previous state.

Import	Import data into the selected table or import schema data into the selected dictionary.

 Database Explorer user interface


SpeedMenu (Enter SQL)
SpeedMenu commands (Enter SQL)

When you highlight an object in Enter SQL tabbed page, you can right-click it to display a SpeedMenu of commands that can be used to edit the SQL statement in the window.

Pop-up command	Description

Cancel	Undo last command or revert to previous state

Cut	Copy and remove the selected text.

Copy	Copy the selected text.

Paste	Paste the selected text.

Delete	Delete the selected text.

Select All	Select all text in the Enter SQL window.

Load from file	Load SQL statements from a text file.

Save to file	Save the SQL statements entered in this window to a text file.

Execute	Execute the current SQL statement

 Database Explorer user interface


Key commands

You can expand and contract the hierarchy of objects in the left pane by using the following keystrokes.

To do this...	Press this key...

Expand object (display child objects)	+ (plus sign) or Right key
Contract object (hide child objects)	- (minus sign) or Left key
Show entire tree (display all levels)	* (asterisk)
 Database Explorer user interface


Data Dictionary

A data dictionary is a special database used to store attribute sets for field components in C++Builder datasets. An attribute set describes a field component's properties, field type, and the type of visual control to create when the field component is dragged onto a form. By storing attribute sets in a  data dictionary, you need only set properties once for a single component, and can then apply the attribute set to other field components that should share the same properties.

Attribute sets can be created for any database. You can derive attribute sets from an existing database by importing the database into the data dictionary, or you can create attribute sets directly from the Fields editor when working with a data set in a data module or form.

 Dictionary topics


Creating a data dictionary

To create a new data dictionary:

1.	Click the Dictionary tab in the left pane.

2.	Select the Dictionary object in the left pane.

3.	Right-click the Dictionary object to invoke the SpeedMenu.

4.	Select New from the SpeedMenu to display the Create a new Dictionary dialog box.

5.	Enter a name for the dictionary in the Dictionary Name edit box.

6.	Select the dictionary database alias from the Database list box.

7.	Enter a table name for the dictionary's data in the Table Name edit box.

8.	Optionally enter a description of the data dictionary in the Description memo box.

Once you have added the required information, click OK.

 Dictionary topics


Importing attribute sets into a data dictionary

To import attribute sets into a data dictionary:

1.	Choose Import Database from the Dictionary menu. The Import Dictionary dialog box appears.

2.	Select or enter the dictionary from which to import attribute sets and choose OK.

 Dictionary topics


Updating attribute sets

To modify an attribute set:

1.	Expand the Dictionary object in the left pane until it the Attribute Sets object.

2.	Click the plus sign beside the Attribute Sets object to display available attribute sets.

3.	Select the attribute set to modify in the left pane. The Definitions page appears in the right pane.

4.	Edit the desired attribute set properties.

5.	Right-click the attribute set to invoke the SpeedMenu, and choose Apply to apply your edits to the attribute set.

 Dictionary topics


Creating a new attribute set

To create a new attribute set:

1.	Expand the Dictionary object in the left pane until it the Attribute Sets object.

2.	Right-click the Attribute Sets object to invoke the SpeedMenu, and choose New. The Definition page appears in the right pane.

3.	Enter a name for the attribute set in the left pane.

4.	Optionally specify a TField Class for the attribute set on the Definitions page in the right pane. The TField Class specifies the type of field component to create for a data field added to a dataset.

5.	Optionally specify a TControl Class for the attribute set on the Definitions page. The TControl Class specifies the type of data-aware control to insert in a form when fields that use this attribute set are dragged from the Fields editor to a form.

6.	Set the properties for the attribute set in the Definitions page.

7.	Right-click the attribute set object in the left pane to invoke the SpeedMenu, and choose Apply to add the attribute set to the Attribute Sets object.

 Dictionary topics


Attribute Set

An attribute set in a data dictionary corresponds to the field type, properties, and the data-aware control that should be automatically created for a TField object when it is dragged to a form from the Fields editor at design time.

You can create attribute sets in the Database Explorer, or from the Fields editor.

To create an attribute set from the Fields editor:

1.	Set the properties for a field component using the Object Inspector.

2.	Right-click the field in the Fields editor to invoke the SpeedMenu.

3.	Choose Save to assign the attribute set the same name as the field or choose Save As to specify a different name for the attribute set.

When an attribute set is selected in the Database Explorer's left pane, the parameters for the attribute set appear on the Definitions page in the right pane.  You can edit these parameters as needed. The following table lists the parameters for an attribute set and describes what they are used for:

Attribute	Definition

TField Class	The type of a field to create when a field is added to a dataset.
Blank yields a default TField depending on the physical data type.

TControl Class	The type of a control to create when you drag a field onto a form.
Blank yields a default TControl depending on the type of the TField.

Alignment	Used to center, left- or right-align data in an edit or grid control.

DisplayLabel	The column heading for a field displayed by a grid component. If DisplayLabel is empty, the FieldName property is used to supply the column heading.

DisplayWidth	The number of characters used to display a field in a grid control.

ReadOnly	True/False. Determines if the field is read only.

Required	True/False. Determines if a field value must be entered in a control.

Visible	True/False. Determines if a field is available for display in a grid control.

Transliterate	True/False. Determines if a field's type is translated as necessary between types in different databases.

EditMask	The mask used to limit data that can be put into a masked edit box or entered into a data field.

DisplayFormat	Used to format the value of a field for display purposes.

EditFormat	Used to edit the format of a field.

MaxValue	The maximum value allowed in a field.

MinValue	The minimum value allowed in a field.

Currency	True/False. Indicates if the field is a currency field.

Precision	Used in formatting numeric fields. The value of Precision is the number of decimal places to the right of the decimal point the numeric value should be formatted before rounding.

DisplayValues	Controls how a TBoolean field is translated to and from display format.

BlobType	Specifies the type of blob associated with a memo or graphic control.

Based On	Specifies another attribute set upon which this one is based. Changed made to properties in this attribute set override those in the attribute set upon which it is based.

Note:	Not all properties apply to all fields that use an attribute set. For example, if you specify a MaxValue property in the attribute set, but then apply the set to a TStringField object, MaxValue is ignored.

 Dictionary topics


Applying an attribute set to a TField object

To apply an attribute set to a TField object:

1.	Double-click a dataset to invoke the Fields editor.

2.	Select the field to which to apply the attribute set.

3.	Right-click the field to invoke the SpeedMenu.

4.	Choose Associate attributes.

5.	Select or enter the attribute set to apply from the Attribute set name dialog box. If there is an attribute set in the data dictionary that has the same name as the current field, that attribute set's name appears in the combo box.

 Dictionary topics


Working with database aliases

You can use the Database Explorer to view, create, and modify Borland Database Engine (BDE) aliases.  The following table lists each task and briefly describes the steps needed to accomplish it:

Task...	Instructions...

View aliases...	1.	Click the plus sign beside a database object in the left pane to see a list of alias objects.

2. 	Select the alias to view in the left pane. The Definitions page appears in the right pane.

Create an alias...	1.	Select a database object in the left pane.

2.	Right-click to invoke the SpeedMenu.

3.	Choose New.

4.	Select an alias type in the New Database Alias dialog box and choose OK.

5.	Type a name for the alias in the left pane.

6.	Enter a path for the alias in the PATH parameter on the Definitions page in the right pane. Optionally specify a driver in the Default Driver parameter.

7.	Right-click the database object in the left pane to invoke the SpeedMenu and choose Apply to update the database.

Modify an alias...	1.	Select the alias to modify in the left pane. The Definitions page appears in the right pane.

2.	Edit the PATH and Default Driver parameters as desired.

3.	Right-click the database object in the left pane to invoke the SpeedMenu and choose Apply to update the database.

Delete an alias...	1.	Select the alias to delete in the left pane.

2.	Right-click to invoke the SpeedMenu.

3.	Choose Delete to remove the alias.

4.	Right-click the database object to invoke the SpeedMenu and choose Apply to update the database.


Working with table data

You can use the Database Explorer to view, edit, insert, and delete data in tables.  The following table lists each task and briefly describes the steps needed to accomplish it:

Task...	Instructions...

View table data...	1.	Select a table to view in the left pane.

2.	Click the Data page tab in the right pane to view a scrollable grid of all data in the table.

3.	Use the navigator buttons at the right side of the Database Explorer SpeedBar to scroll from record to record.

Edit a record...	1.	Edit the record's fields in the grid.

2.	To post the edits to the database, select a different record in the grid or click the navigator's Post button in the SpeedBar.

3.	To cancel an edit before moving to another record click the navigator's Cancel button in the SpeedBar or press ESC.

Insert a new record...	1.	Place the cursor on the row before which you wish to insert another row.

2.	Click the navigator's Insert button in the SpeedBar. A blank row appears.

3.	Enter data for each column. Move between columns with the mouse, or by tabbing to the next field.

4.	To post the insert to the database, select a different record in the grid or click the navigator's Post button in the SpeedBar.

5.	To cancel an insert before moving to another record click the navigator's Cancel button in the SpeedBar or press ESC.

Delete a record...	1.	Place the cursor on the row you wish to delete.

2.	Click the navigator's Delete button in the SpeedBar.


Entering SQL statements

The SQL Explorer permits you to make SQL queries against an SQL database on a remote server. In C++Builder Client/Server Suite and C++Builder Professional the Database Explorer permits you to make queries against Paradox and dBASE tables.

To query a database using SQL:

1.	Select a database object in the left pane.

2.	Click the Enter SQL tab in  the right pane to display an edit box where you can enter an SQL statement to execute.

3.	Enter an SQL statement in the edit box. If you  enter statements that write to a table, such as INSERT, UPDATE, or DELETE, be sure to uncheck the Options|LIve Query before executing the statement.

4.	Click the lighting button to execute the query.

You can copy SQL statements from text files, a Help window, or other applications and paste them into the edit box.  See SpeedMenu commands (Enter SQL) for more information about copying, pasting, and loading SQL statements from a file.

Note:	If the SQL syntax you enter is incorrect, an error message is generated.  You can freely edit the Enter SQL field to correct syntax errors.


Using the Blob Explorer dialog box

The Blob Explorer dialog box is used to display the contents of memo or graphics data in a blob field. While you can open the Blob Explorer dialog box at any time, it is only meaningful when you are browsing or editing blob data in a table. When you select a table containing a blob field, the blob data is displayed in this dialog box.

If the field is a TGraphicsField, the dialog box attempts to display the graphic. If the field is a TMemoField, the dialog box attempts to display the blob text. For other blob field types, the dialog box is empty. If you know the contents of another field type is text or graphics, you can right-click the dialog box to invoke a SpeedMenu from which you can choose Show as text or Show as graphic to force display of the field.


Using the Import Database dialog box

The Import Database dialog box is used to specify the name of an existing database whose column attributes you want to import into the current data dictionary as attribute sets. Enter or select the name of an existing data dictionary in the Database Name combo box.


Using the Export Dictionary to a File dialog box

The Export Dictionary to a File dialog box is used to specify how and where to export a data dictionary in Borland Dictionary Export File (.BDX) format. The following table lists the controls for this dialog box and explains how they are used.

Control	Purpose

Export File edit box	Specifies the name of the export file to create.

Browse button	Displays the Export File dialog box. This is basically the standard File Save dialog box (available as a component on the Dialogs page of the Component Palette). The Files of type combo box, however, is preset to search for files in Borland Dictionary Export format (.BDX). When you choose a file in this dialog, it is inserted into the Export File edit box in the Export Dictionary to a File dialog box.

Export type radio buttons	Specifies the type of dictionary data to export. Choices are:

1.	All Dictionary contents. This option exports all attribute sets for all available databases.

2.	Selected databases. This option enables you to specify the databases from which to export attribute sets.

3.	Selected attribute sets. This option enables you to specify which attribute sets belonging to a single database are to be exported.

Export List list box	Enables you to multi-select databases or attribute sets to export.


Using the New Database Alias dialog box

The New Database Alias dialog box is used to specify the name of a new database alias to create. Enter  the name of an new alias in the Database Alias edit box.


Using the Select a Dictionary dialog box

The Select a Dictionary dialog box is used to specify the name of an existing data dictionary you want to make the active dictionary. Enter or select the name of an existing data dictionary in the Dictionary Name combo box.


Using the Unregister a Dictionary dialog box

The Unregister a Dictionary dialog box is used to specify the name of an existing data dictionary you want to remove from the Object Repository. Enter or select the name of an existing data dictionary in the Dictionary Name combo box.


Using the Delete a Dictionary dialog box

The Delete a Dictionary dialog box is used to specify the name of an existing data dictionary you want to delete. Enter or select the name of an existing data dictionary in the Dictionary Name combo box.


Using the Register an existing Dictionary dialog box

The Register an existing Dictionary dialog box is used to specify information about an existing data dictionary you want to store in the Object Repository. Follow these steps to register a data dictionary:

1.	Enter a name for the dictionary in the Dictionary Name edit box.

2.	Select the dictionary database alias from the Database list box.

3.	Enter or select a table name for the dictionary's data in the Table Name edit box.

4.	Optionally enter a description of the data dictionary in the Description memo box.

5.	Once you have added the required information, click OK.


Using the Create a new Dictionary dialog box

The Create a new Dictionary dialog box is used to specify information about the new data dictionary you want to create. Follow these steps to create the new data dictionary:

1.	Enter a name for the dictionary in the Dictionary Name edit box.

2.	Select the dictionary database alias from the Database list box.

3.	Enter or select a table name for the dictionary's data in the Table Name edit box.

4.	Optionally enter a description of the data dictionary in the Description memo box.

5.	Once you have added the required information, click OK.


Using the Save Query dialog box

The Save Query dialog box is basically the standard File Save dialog box (available as a component on the Dialogs page of the Component Palette). The Files of type combo box, however, is preset to save the current text in the edit box on the Enter SQL page in the right pane of the Database Explorer as a text file with an extension of .SQL.


Using the Load Query dialog box

The Load Query dialog box is basically the standard File Open dialog box (available as a component on the Dialogs page of the Component Palette). The Files of type combo box, however, is preset to look for text files with an extension of .SQL. It is assumed each such file contains a valid SQL query that can be read into the query edit box on the Enter SQL page in the right pane of the Database Explorer.


Using the Import from File into Dictionary dialog box

The Import from File into Dictionary dialog box is basically the standard File Open dialog box (available as a component on the Dialogs page of the Component Palette). The Files of type combo box, however, is preset to look for flat files with the Borland Dictionary Export Files extension (.BDX). This file type contains previously a previously exported data dictionary.


Using the Database Explorer SpeedBar

The Database Explorer SpeedBar contains the following buttons for executing commands:

Button	Command

Open	Open a new object.

Delete	Delete a selected object (does not apply to data edited on the Data page in the right pane of the Database Explorer).

Cancel	Abandon modifications to a selected object (does not apply to data edited on the Data page in the right pane of the Database Explorer).

Apply	Commit modifications of a selected object to the database (does not apply to data edited on the Data page in the right pane of the Database Explorer).

Explore Blobs	Displays a form for displaying text and graphics blobs associated with data in a table.

When the Data page is displayed in the right pane of the Database Explorer, the SpeedBar also contains a data-aware navigator control with the following buttons that enable you to edit records:

Button	Command

First	Go to first record.

Prior	Go to previous record.

Next	Go to next record.

Last	Go to last record.

Insert	Insert a new record.

Delete	Delete the current record.

Edit	Edit the current record.

Post	Post a changed record to the database.

Cancel	Abandon editing or inserting of a record.

Refresh	Fetch a new view of data from the database.